//
// Created by Administrator on 2025/9/1.
//

#include "LeetCode.h"
#include "vector"
#include "iostream"


float leetCode::test1(std::vector<int> &v1, std::vector<int> &v2) {
    for (int i = 0; i < v2.size(); i++) {
        v1.push_back(v2[i]);
    }
    for (int i = 0; i < v1.size(); i++) {
        for (int j = 0; j < v1.size(); j++) {
            if (v1.size() - 1 != j && v1[j] > v1[j + 1]) {
                std::swap(v1[j], v1[j + 1]);
            }
        }
    }
    if (v1.size() % 2 == 0) {
        int position = (v1.size() - 1) / 2;
        return (v1[position] + v1[position + 1]) / 2.0;
    } else {
        return v1[(v1.size() - 1) / 2];
    }
}

bool leetCode::test2(std::string &s1, std::string &p) {
    //cab c*
    char singleChar = '.', multiChar = '*';
    if (s1 == p) {
        return true;
    }
    int i = 0, j = i;
    std::vector<std::vector<bool>> v(s1.size() + 1, std::vector<bool>(p.size() + 1));
    v[0][0] = true;
    while (i < p.size()) {
        char c = p.at(i);
        if (c == singleChar) {
            if (j < s1.size()) {
                v[i][j] = true;
            }
            i++;
            j++;
        } else if (c == multiChar) {
            if (j < s1.size()) {
                v[i][j] = true;
                j++;
            } else {
                i++;
            }
        } else {
            if (j < s1.size() && c == s1.at(j)) {
                v[i][j] = true;
            }
            i++;
            j++;
        }
    }
    return true;
}
